﻿using EA.BA;
using EA.Common;
using EA.DTO;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace EAAdmin
{
    public partial class Login : WebPage
    {
        override
        protected void Load(object sender, EventArgs e)
        {
            
        }

        public void SignIn(HttpRequest Request,HttpResponse Response)
        {
            String username = Request["username"];
            String password = Request["password"];
            
            if (username == null || username.Equals(""))
            {
                this.error("Username can be not empty");
            }
            else if (password == null || password.Equals(""))
            {
                this.error("Password can be not empty");
            }

            MemberBA memberBA = new MemberBA();
            MemberTO user = memberBA.GetMemberByUsername(username);
            if (username.Equals(user.UserName) && Md5.md5(password).Equals(user.Password))
            {
                Session["ROLE_ID"] = user.Role;
                Session["ID"] = user.ID;
                Response.Redirect("/Default.aspx");
            }
            else
            {
                this.isLoad = true;
                this.error("Login failed");
            }
        }
    }
}
